﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Teigha.Core;

namespace Teigha.TD
{
	public class ExStringIO : OdEdBaseIO
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public ExStringIO(IntPtr cPtr, bool cMemoryOwn) : base(TD_DbPINVOKE.ExStringIO_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(ExStringIO obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~ExStringIO()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							TD_DbPINVOKE.delete_ExStringIO(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public void reset(string sInput)
		{
			TD_DbPINVOKE.ExStringIO_reset(this.swigCPtr, sInput);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public string getInitString()
		{
			string result = TD_DbPINVOKE.ExStringIO_getInitString(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static ExStringIO create(string filename)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr intPtr = TD_DbPINVOKE.ExStringIO_create(filename);
			ExStringIO result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject(Teigha.Core.Helpers.odrxCreateObjectInternal(intPtr, true));
				result = new ExStringIO(intPtr, false);
			}
			else
			{
				Teigha.Core.Helpers.odrxCreateObjectInternal(intPtr, true);
				result = new ExStringIO(intPtr, false);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual string getString(string prompt, int options, OdEdStringTracker pTracker)
		{
			string result = TD_DbPINVOKE.ExStringIO_getString__SWIG_0(this.swigCPtr, prompt, options, OdEdStringTracker.getCPtr(pTracker));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual string getString(string prompt, int options)
		{
			string result = TD_DbPINVOKE.ExStringIO_getString__SWIG_1(this.swigCPtr, prompt, options);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual string getString(string prompt)
		{
			string result = TD_DbPINVOKE.ExStringIO_getString__SWIG_2(this.swigCPtr, prompt);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual void putString(string arg0)
		{
			TD_DbPINVOKE.ExStringIO_putString(this.swigCPtr, arg0);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public bool isEof()
		{
			bool result = TD_DbPINVOKE.ExStringIO_isEof(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual uint getKeyState()
		{
			uint result = TD_DbPINVOKE.ExStringIO_getKeyState(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		private object locker = new object();

		private HandleRef swigCPtr;
	}
}
